<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<% String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName();%>
<head>
    <%@ include file="/WEB-INF/jsp/other/head.jsp" %>
    <link rel="stylesheet" href="<%=basePath%>/wxAssets/css/public.css">
    <link rel="stylesheet" href="<%=basePath%>/wxAssets/css/common/header_type_1.css?t=2">
    <link rel="stylesheet" href="<%=basePath%>/wxAssets/css/index.css?t=4">
    <link rel="stylesheet" href="<%=basePath%>/wxAssets/css/weui.min.css">
    <link rel="stylesheet" href="<%=basePath%>/wxAssets/css/popup.css">
</head>
<body>
<div id="loading"></div>
<div class="popup_info" style="height: 100%">
    <div class="header">
        <div class="header_img">
            <img src="${head_img}" width="100%" height="100%">
        </div>
        <input id="name" class="weui-input person_name" type="text" placeholder="请输入您的昵称!">
        <svg class="icon icon_update" aria-hidden="true" onclick="show_focus()">
            <use xlink:href="#iconxiugaigerenziliao"></use>
        </svg>
    </div>
    <div class="weui_example">
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <svg class="icon" aria-hidden="true">
                    <use xlink:href="#icondingdan"></use>
                </svg>
                <div class="choose_name">绑定手机:</div>
            </div>
            <div class="weui-cell__bd">
                <input class="weui-input" id="telphone" type="tel" maxlength="11" placeholder="请输入手机号码">
            </div>
        </div>
    </div>
    <div class="weui_example">
        <div class="weui-cell" >
            <div class="weui-cell__hd">
                <svg class="icon" aria-hidden="true">
                    <use xlink:href="#iconpinglun"></use>
                </svg>
                <div class="choose_name">绑定车牌:</div>
            </div>
            <div class="weui-cell__bd">
                <input class="weui-input" id="car_no" type="text" maxlength="8" placeholder="请输入车牌号码">
            </div>
        </div>
    </div>
    <div class="btn_submit" onclick="update_user()">确认修改</div>
</div>
<%--
<div id="container">
    <div class="header">
        <div class="header_onclick" onclick="to_vip()"></div>
        <div class="header_img">
            <img src="${mainWxUserPO.head_img}" width="100%" height="100%">
        </div>
        <div class="header_name">
            <div class="header_wx_name">${mainWxUserPO.wx_name }
                <span class="header_wx_name_img"></span>
            </div>
            <div class="header_wx_msg">
                <c:if test="${car_no != '' && car_no != null && car_no != undefined}">
                    <span class="header_wx_msg_car">${car_no_text}</span>
                </c:if>
                <c:if test="${car_no != '' && car_no != null && car_no != undefined}">
                    <span class="header_wx_msg_phone">${mainWxUserPO.telphone}</span>
                </c:if>
            </div>
            <div class="header_money" style="">余额(元):${balance}</div>
        </div>
    </div>

    <div class="content_two">
        <div class="weui-grids">
            <a href="javascript:goRouter('wxUserService.move_car_init');" class="weui-grid">
                <div class="weui-grid__icon">
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#iconnuoche"></use>
                    </svg>
                </div>
                <p class="weui-grid__label">挪车</p>
            </a>
            <a href="javascript:goRouter('wxMainRepairShopService.repairShop_init');" class="weui-grid">
                <div class="weui-grid__icon">
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#iconchuxian"></use>
                    </svg>
                </div>
                <p class="weui-grid__label">出险</p>
            </a>
            <a href="javascript:goRouter('wxUserService.order_init');" class="weui-grid">
                <div class="weui-grid__icon">
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icondingdan"></use>
                    </svg>
                </div>
                <p class="weui-grid__label">工单</p>
            </a>
            <a href="javascript:goRouter('wxUserService.all_comment_init');" class="weui-grid">
                <div class="weui-grid__icon">
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#iconpinglun"></use>
                    </svg>
                </div>
                <p class="weui-grid__label">评论</p>
            </a>
            <a href="javascript:weui.alert('已通知，稍后客服联系您！');"  class="weui-grid">
                <div class="weui-grid__icon">
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#iconkefu"></use>
                    </svg>
                </div>
                <p class="weui-grid__label">客服</p>
            </a>
            <a onclick="open_update_person()" class="weui-grid">
                <div class="weui-grid__icon">
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#iconxiugaigerenziliao"></use>
                    </svg>
                </div>
                <p class="weui-grid__label">修改</p>
            </a>
        </div>
    </div>
    <div class="content_three">
        <div class="content_three_img"></div>
    </div>
</div>
--%>

</body>
<script type="text/javascript" src="//at.alicdn.com/t/font_1174287_0xbi9o97nge.js"></script>
<script type="text/javascript" src="<%=basePath%>/wxAssets/js/weui.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/wxAssets/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/wxAssets/js/toast_min.js"></script>
<script type="text/javascript" src="<%=basePath%>/wxAssets/js/publicJSFunction.js?t=15"></script>
<script type="text/javascript" src="<%=basePath%>/wxAssets/js/zepto.min.js?t=15"></script>
<script type="text/javascript" src="<%=basePath%>/wxAssets/js/popup.js?t=15"></script>
<script type="text/javascript">
    var loading = weui.loading('页面加载中');
    var openid = '${openid}';
    var name = '${name}';
    var tel = '${telphone}';
    var parkCarno = '${parkCarno}';
    var parkId = '${parkId}';
    var newBinding = '${newBinding}';

    $(function(){
        $('#name').val(name);
        $('#telphone').val(tel);
        $('#car_no').val(parkCarno);

        if(1 == newBinding){
            $('.btn_submit').html("确认修改");
        }else{
            $('.btn_submit').html("确认绑定");
        }

        loading.hide(function() {
            $('#loading').addClass('weui-animate-fade-out').on('animationend webkitAnimationEnd', function () {
                $('#loading').remove();
            });
        });
    });

    //打开修改窗口
    /*function open_update_person(){
        if('' != name && null != name && undefined != name){
            $('#name').val(name);
            $('#name').attr("readOnly","true");
        }
        if('' != tel && null != tel && undefined != tel){
            $('#telphone').val(tel);
        }
        if('' != car_no && null != car_no && undefined != car_no){
            $('#car_no').val(car_no);
        }
        $('.popup_info').open_popup();
    }*/

    //关闭
    /*function close_update_person(){
        if('' == name || null == name || undefined == name || '' == tel || null == tel || undefined == tel
            || '' == car_no || null == car_no || undefined == car_no){
            return;
        }
        $('.popup_info').close_popup();
    }*/

    function show_focus(){
        $('#name').attr("readOnly",false);
        $('#name').focus();
    }

    //修改用户信息
    function update_user(){
        var name = $('#name').val();
        if('' == name || null == name || undefined == name){
            $.toast_min('请输入您的昵称！',1000);
            return;
        }
        var telphone = $('#telphone').val();
        if('' == telphone || null == telphone || undefined == telphone){
            $.toast_min('请输入手机号码！',1000);
            return;
        }

        //手机号码
        var testMobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
        if(null == telphone || !11 === telphone.length || !testMobile.test(telphone)){
            $.toast_min('请输入正确的手机号码!',1000);
            return;
        }

        //车牌校验
        var parkCarno = $('#car_no').val().toUpperCase();
        if('' == parkCarno || null == parkCarno || undefined == parkCarno){
            $.toast_min('请输入车牌号码！',1000);
            return;
        }
        if(7 > parkCarno.replace(/(^\s+)|(\s+$)/g,"").length){
            $.toast_min('请输入正确的车牌号码!',1000);
            return;
        }

        var xreg=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{5}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
        var creg=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
        if(parkCarno.length == 7){
            if (!creg.test(parkCarno)) {
                $.toast_min('请输入正确的车牌号码!',1000);
                return;
            }
        } else if(parkCarno.length == 8){
            if (!xreg.test(parkCarno)) {
                $.toast_min('请输入正确的车牌号码!',1000);
                return;
            }
        }

        //校验车牌号码格式
        var re = /^[a-zA-Z0-9\u4e00-\u9fa5]+$/;
        if (!re.test(parkCarno.replace(/(^\s+)|(\s+$)/g,""))){
            $.toast_min('请输入正确格式的车牌号码!',1000);
            return;
        }

        var loading_1 = weui.loading('处理中...');
        $.ajax({
            url: '<%=path%>/wechat/mainWxUser/Binding',
            data:JSON.stringify({'name':name,'telphone':telphone,'parkCarno':parkCarno,'openid':openid,'parkId':parkId,'newBinding':newBinding}),
            type:'post',
            contentType: 'application/json',
            success: function (data) {
                var data = data.data;
                loading_1.hide(function() {
                    if(data.appcode == -1){
                        weui.alert(data.appmsg);
                        return
                    }else{
                        weui.alert(data.appmsg,function(){
                            goUrl('/wechat/mainWxUser/initSuccess?newBinding='+newBinding);
                            return;
                        });
                    }
                })
            }
        })
    }
</script>
</html>